/*
 * bmckune_prints.h
 *
 *  Created on: Sep 4, 2011
 *      Author: ibyte
 */

#ifndef PRINTS_H_
#define PRINTS_H_

#include "common.h"

#ifdef true
#define DEBUG(args) (printf("DEBUG: "), printf args)
#else
#define DEBUG(args)
#endif

static void print(const char* line);

static void printCredentials(const char* assignment, const char* dateCompleted){
	printf("|*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^**^*^*^*^|\n");
	printf("|Name:\t\tBrandon McKune\t\t\t\t\t|\n");
	printf("|Class:\t\tCSc8370 - Data Security\t\t\t\t|\n");
	printf("|Date:\t\t%s\t\t\t\t|\n", dateCompleted);
	printf("|Assignment:\t%s\t\t\t\t\t|\n", assignment);
	printf("|*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*|\n");
}

static void printQuestion(const int number, const char* question){
	printf("Question %d:\n", number);

	print(question);
}

static void printAnswer(const char* answerLine){
	printf("Answer:\n");
	print(answerLine);
}

static void print(const char* line){
	uint64_t textLength = 72 - 6; //72 normal line size, 6 for tab size
	uint64_t lineSize = strlen(line);

	//Move the text poitned at line to scoped array.
	char textToPrint[lineSize];
	char print[textLength + 2];

	memcpy(textToPrint, line, lineSize);

	uint64_t textIndex = 0;
	uint64_t printIndex = textLength;

	while(textIndex < lineSize){
		//Fill in a space to start and null termination.
		print[0] = ' ';
		print[textLength + 2] = '\0';

		if((lineSize - textIndex) < (textLength - 1)){
			memcpy(&print[1], &textToPrint[textIndex], (lineSize-textIndex));
			for(uint64_t i = (lineSize-textIndex + 1); i < textLength; i++){
				print[i] = '\0';
			}

			textIndex += (lineSize-textIndex);
		}else{

			memcpy(&print[1], &textToPrint[textIndex], textLength);
			textIndex += textLength;

			for(uint64_t i = 0; i < textLength; i++){
				if(print[printIndex] != '\0' && print[printIndex] != ' '){
					print[printIndex] = '\0';
					printIndex--;
					textIndex--;
				}else{
					i = textLength;
				}
			}

			printIndex = textLength;
		}
		printf("%s\n", print);
	}
}

#endif /* PRINTS_H_ */
